﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}
@System.Web.Optimization.Styles.Render("~/Content/scripts/plugins/jqgrid/css")
@System.Web.Optimization.Scripts.Render("~/Content/scripts/plugins/jqgrid/js")
<script>
    var keyValue = request('keyValue');
    var postData = "";
    var pollingObjectData = "";
    var AllAuthorizeCheckData = {};
    var isBool = false;
    var list = [];
    var _TypeId = "", _ItemId = "", _ObjectId = "";
    $(function () {
        $('#step-1 .panel-body').height($(window).height() - 228);
        $('#Description').height($(window).height() - 385);
        $('#step-2 .standtabborder').height($(window).height() - 131);
        $('#DesignateMemberlist').height($(window).height() - 141);
        $('#step-3 .tab-content').height($(window).height() - 167);
        //加载导向
        $('#wizard').wizard().on('change', function (e, data) {
            var $finish = $("#btn_finish");
            var $last = $("#btn_last");
            var $next = $("#btn_next");
            if (!!data.direction) {
                
                switch (data.currentStep - 1) {
                    case 1:
                        if (!bindingBase()) {
                            return false;
                        }
                        InitPollingObject();
                        $finish.attr('disabled', 'disabled');
                        $next.removeAttr('disabled');
                        isBool = false;
                        $("#publish_panel").css("top", "650px");
                        break;
                    case 2:
                        InitPollingItem();
                        $finish.attr('disabled', 'disabled');
                        $next.removeAttr('disabled');
                        isBool = false;
                        $("#publish_panel").css("top", "650px");
                        break;
                    case 3:
                        if (!$('#PollingItem').Validform()) {
                            return false;
                        }
                        $finish.removeAttr('disabled');
                        $next.attr('disabled', 'disabled');
                        isBool = false;
                        $("#publish_panel").css("top", "650px");
                        break;
                    default:
                        $finish.attr('disabled', 'disabled');
                        $next.removeAttr('disabled');
                        break;
                }
            }
        });
        GetRole();
        //获取表单
        if (!!keyValue) {
            $.SetForm({
                url: "../../PropertyManage/CS_PollingBussiness/GetEntity",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data.Entity);
                    list = data.list;
                    if (data.TypeIds.indexOf("9b5a3e03-499b-4003-9b11-9558191d7b2c") >= 0) {
                        $("#9b5a3e03-499b-4003-9b11-9558191d7b2c").attr("checked", 'checked');
                    }
                    if (data.TypeIds.indexOf("fa7addca-b7d8-4a42-91ce-8499323013c7") >= 0) {
                        $("#fa7addca-b7d8-4a42-91ce-8499323013c7").attr("checked", 'checked');
                    }
                    if (data.TypeIds.indexOf("644d52f3-772a-421c-9df2-a4ee5ffc2f91") >= 0) {
                        $("#644d52f3-772a-421c-9df2-a4ee5ffc2f91").attr("checked", 'checked');
                    }
                    if (data.TypeIds.indexOf("be7352e1-4ace-4fe9-bc0f-767aa70e3ac0") >= 0) {
                        $("#be7352e1-4ace-4fe9-bc0f-767aa70e3ac0").attr("checked", 'checked');
                    }
                    if (data.TypeIds.indexOf("7c38d876-2f54-4783-b26a-b194f2bad634") >= 0) {
                        $("#7c38d876-2f54-4783-b26a-b194f2bad634").attr("checked", 'checked');
                    }
                    if (data.TypeIds.indexOf("d56675f0-e574-42a5-9d2a-6874672bf561") >= 0) {
                        $("#d56675f0-e574-42a5-9d2a-6874672bf561").attr("checked", 'checked');
                    }
                    if (!!data.Entity.GenerateMemo) {
                        var GenerateMemo = eval('(' + data.Entity.GenerateMemo + ')');
                        $("#publish_panel").SetWebControls(GenerateMemo);
                    }
                    $("#ExecRole").setCheckedNodes(data.Entity.ExecRole.split(","));
                }
            });
        }
    });

    //获取巡检专业
    var Types = [];
    function GetPollingType() {
        Types = [];
        var checkboxs = document.getElementsByName("checktype");
        for (var i = 0; i < checkboxs.length; i++) {
            if (checkboxs[i].checked) {
                Types.push(checkboxs[i].id);
            }
            else {
                var index = Types.toString().indexOf(checkboxs[i].id);
                //if (index > -1)
                //    Types.remove(checkboxs[i].id);
            }
        }
        
        if (Types.length > 0) {
            $('#decorate1').show();
            $('#room1').show();
            $('#device1').show();
            $('#area1').show();
            $('#area2').show();
            $('#area3').show();
            $('#Itemdecorate1').show();
            $('#Itemroom1').show();
            $('#Itemdevice1').show();
            $('#Itemarea1').show();
            $('#Itemarea2').show();
            $('#Itemarea3').show();
            if (Types.toString().indexOf("9b5a3e03-499b-4003-9b11-9558191d7b2c") <= -1) {
                $('#decorate1').hide(); $('#Itemdecorate1').hide();//$('#DecorateBill').hide(); $('#DecorateBillDiv').hide();
            }
            if (Types.toString().indexOf("fa7addca-b7d8-4a42-91ce-8499323013c7") <= -1) {
                $('#room1').hide(); $('#Itemroom1').hide();
            }
            if (Types.toString().indexOf("644d52f3-772a-421c-9df2-a4ee5ffc2f91") <= -1) {
                $('#device1').hide(); $('#Itemdevice1').hide();
            }
            if (Types.toString().indexOf("be7352e1-4ace-4fe9-bc0f-767aa70e3ac0") <= -1) {
                $('#area1').hide(); $('#Itemarea1').hide();
            }
            if (Types.toString().indexOf("7c38d876-2f54-4783-b26a-b194f2bad634") <= -1) {
                $('#area2').hide(); $('#Itemarea2').hide();
            }
            if (Types.toString().indexOf("d56675f0-e574-42a5-9d2a-6874672bf561") <= -1) {
                $('#area3').hide(); $('#Itemarea3').hide();
            }
        }
    }

    /*第一步配置*/
    function bindingBase() {
        GetPollingType();
        if (!$('#step-1').Validform() || Types.length < 1) {
            return false;
        }
        var _postData = $("#step-1").GetWebControls(keyValue);
        postData = $.extend(postData, _postData);
        return true;
    }
    /*第二步配置*/
    function InitPollingObject() {
        $(".standtab").removeClass("standtabactived");
        $('.standtab-pane').css('display', 'none');
        $("#Area1Div").css('display', 'none');
        _TypeId = Types[0];
        GetGrid();
        switch (Types[0]) {
            case "9b5a3e03-499b-4003-9b11-9558191d7b2c":
                GetTree('DecorateBill'); $("#DecorateBill").css('display', 'block'); $("#decorate1").addClass("standtabactived"); break;
            case "fa7addca-b7d8-4a42-91ce-8499323013c7":
                GetTree('Room'); $("#Room").css('display', 'block'); $("#room1").addClass("standtabactived"); break;
            case "644d52f3-772a-421c-9df2-a4ee5ffc2f91":
                GetTree('Device'); $("#Device").css('display', 'block'); $("#device1").addClass("standtabactived"); break;
            case "be7352e1-4ace-4fe9-bc0f-767aa70e3ac0":
                GetTree('Area1'); $("#Area1").css('display', 'block'); $("#area1").addClass("standtabactived"); break;
            case "7c38d876-2f54-4783-b26a-b194f2bad634":
                GetTree('Area2'); $("#Area2").css('display', 'block'); $("#area2").addClass("standtabactived"); break;
            case "d56675f0-e574-42a5-9d2a-6874672bf561":
                GetTree('Area3'); $("#Area3").css('display', 'block'); $("#area3").addClass("standtabactived"); break;
            default: break;
        }
    }
    /*第三步配置*/
    function InitPollingItem() {
        $(".standtab").removeClass("standtabactived");
        $('.standtab-pane').css('display', 'none');
        switch (Types[0]) {
            case "9b5a3e03-499b-4003-9b11-9558191d7b2c":
                _TypeId = "9b5a3e03-499b-4003-9b11-9558191d7b2c"; TabItem('ItemDecorateBillDiv'); $("#ItemDecorateBill").css('display', 'block'); $("#Itemdecorate1").addClass("standtabactived"); return;
            case "fa7addca-b7d8-4a42-91ce-8499323013c7":
                _TypeId = "fa7addca-b7d8-4a42-91ce-8499323013c7"; TabItem('ItemRoomDiv'); $("#ItemRoom").css('display', 'block'); $("#Itemroom1").addClass("standtabactived"); return;
            case "644d52f3-772a-421c-9df2-a4ee5ffc2f91":
                _TypeId = "644d52f3-772a-421c-9df2-a4ee5ffc2f91"; TabItem('ItemDeviceDiv'); $("#ItemDevice").css('display', 'block'); $("#Itemdevice1").addClass("standtabactived"); return;
            case "be7352e1-4ace-4fe9-bc0f-767aa70e3ac0":
                _TypeId = "be7352e1-4ace-4fe9-bc0f-767aa70e3ac0"; TabItem('ItemArea1Div'); $("#ItemArea1").css('display', 'block'); $("#Itemarea1").addClass("standtabactived"); return;
            case "7c38d876-2f54-4783-b26a-b194f2bad634":
                _TypeId = "7c38d876-2f54-4783-b26a-b194f2bad634"; TabItem('ItemArea2Div'); $("#ItemArea2").css('display', 'block'); $("#Itemarea2").addClass("standtabactived"); return;
            case "d56675f0-e574-42a5-9d2a-6874672bf561":
                _TypeId = "d56675f0-e574-42a5-9d2a-6874672bf561"; TabItem('ItemArea3Div'); $("#ItemArea3").css('display', 'block'); $("#Itemarea3").addClass("standtabactived"); return;
            default: break;
        }
    }


    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $("#jqg_Item");
        $gridTable.jqGrid({
            datatype: "local",
            autowidth: true,
            unwritten: false,
            height: 400,
            toolbar: [true, 'top'],
            colModel: [
                { label: '项目主键', name: 'Id', hidden: true },
                { label: '关联表主键', name: 'OIId', hidden: true },
                { label: '对象主键', name: 'ObjectId', hidden: true },
                { label: '项目名称', name: 'Name', index: 'Name', width: 200, align: 'center', sortable: false },
                { label: '编码', name: 'Code', index: 'Code', width: 200, align: 'center', sortable: false },
                {
                    label: "执行频次", name: "Frenquency", index: "Frenquency", width: 200, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (rowObject.Unit) {
                            case "0": return rowObject.UnitNum + "天" + cellvalue + "次";
                            case "1": return rowObject.UnitNum + "周" + cellvalue + "次";
                            case "2": return rowObject.UnitNum + "月" + cellvalue + "次";
                            case "3": return rowObject.UnitNum + "季" + cellvalue + "次";
                            case "4": return rowObject.UnitNum + "年" + cellvalue + "次";
                            default: return cellvalue;
                        }
                    }
                },
                 { label: '执行次数', name: 'Frequency', index: 'Frequency', editable: true, editrules: { edithidden: true, required: true, number: true }, edittype: "text", width: 150, align: 'center', sortable: false }
            ],
            rowNum: "10000",
            rownumbers: true,
            onSelectRow: function (rowid, status) {
                if (rowid && rowid !== selectedRowIndex && selectedRowIndex != 0) {
                    $gridTable.saveRow(selectedRowIndex);
                    $.each(list, function (i, n) {
                        if ($gridTable.getRowData(selectedRowIndex).Id == n.Id && $gridTable.getRowData(selectedRowIndex).ObjectId == n.ObjectId) {
                            list[i].Frequency = $gridTable.getRowData(selectedRowIndex).Frequency;
                            return false;
                        }
                    });
                }
                selectedRowIndex = $("#" + this.id).getGridParam('selarrrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            ondblClickRow: function (rowid, iRow, iCol, e) {
                $gridTable.editRow(rowid, {
                    keys: true, successfunc: function (response) {
                        $gridTable.jqGrid("saveRow", rowid);
                        $.each(list, function (i, n) {
                            if ($gridTable.getRowData(rowid).Id == n.Id && $gridTable.getRowData(rowid).ObjectId == n.ObjectId) {
                                list[i].Frequency = $gridTable.getRowData(rowid).Frequency;
                                return false;
                            }
                        });
                        return true;
                    }
                });
                selectedRowIndex = rowid;
            }
        });
        $("#t_jqg_Item").css("height", "36px").append("<div class=\"toolbar\" style=\"margin-top:1px;margin-left:1px;\"><div class=\"btn-group\">"
                       + "<a id=\"lr-addRelevanceItem\" class=\"btn btn-default\" onclick=\"btn_addItem()\"><i class=\"fa fa-plus\"></i>&nbsp;新增</a>"
                       + "<a id=\"lr-deleteRelevanceItem\" class=\"btn btn-default\" onclick=\"btn_deleteItem()\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</a>"
                       + "</div></div>");
    }

    //加载表格
    function GetObjectGrid() {
        var _colModel = [];
        var isTrue = false;
        switch (_TypeId) {
            case "9b5a3e03-499b-4003-9b11-9558191d7b2c":
                _colModel = [
                            { label: '项目主键', name: 'Id', hidden: true },
                            { label: '关系表主键', name: 'OIId', hidden: true },
                            { label: '对象主键', name: 'ObjectId', hidden: true },
                            { label: '组织机构ID', name: 'OrganizeId', hidden: true },
                            { label: '名称', name: 'ObjName', index: 'ObjName', width: 200, align: 'center', sortable: false },
                            { label: '编码', name: 'ObjCode', index: 'ObjCode', width: 200, align: 'center', sortable: false },
                            { label: '地址', name: 'Address', index: 'Address', width: 200, align: 'center', sortable: false },
                            { label: '执行次数', name: 'Frequency', index: 'Frequency', editable: true, editrules: { edithidden: true, required: true, number: true }, edittype: "text", width: 150, align: 'center', sortable: false }
                ];
                break;
            case "fa7addca-b7d8-4a42-91ce-8499323013c7":
                _colModel = [
                           { label: '项目主键', name: 'Id', hidden: true },
                           { label: '关系表主键', name: 'OIId', hidden: true },
                           { label: '对象主键', name: 'ObjectId', hidden: true },
                           { label: '组织机构ID', name: 'OrganizeId', hidden: true },
                           { label: '名称', name: 'ObjName', index: 'ObjName', width: 200, align: 'center', sortable: false },
                           { label: '编码', name: 'ObjCode', index: 'ObjCode', width: 200, align: 'center', sortable: false },
                           { label: '地址', name: 'Address', index: 'Address', width: 200, align: 'center', sortable: false },
                           { label: '执行次数', name: 'Frequency', index: 'Frequency', editable: true, editrules: { edithidden: true, required: true, number: true }, edittype: "text", width: 150, align: 'center', sortable: false }
                ];
                break;
            case "644d52f3-772a-421c-9df2-a4ee5ffc2f91":
                _colModel = [
                          { label: '项目主键', name: 'Id', hidden: true },
                          { label: '关系表主键', name: 'OIId', hidden: true },
                          { label: '对象主键', name: 'ObjectId', hidden: true },
                          { label: '组织机构ID', name: 'OrganizeId', hidden: true },
                          { label: '名称', name: 'ObjName', index: 'ObjName', width: 200, align: 'center', sortable: false },
                          { label: '编码', name: 'ObjCode', index: 'ObjCode', width: 200, align: 'center', sortable: false },
                          { label: '执行次数', name: 'Frequency', index: 'Frequency', editable: true, editrules: { edithidden: true, required: true, number: true }, edittype: "text", width: 150, align: 'center', sortable: false }
                ]; break;
            default:
                _colModel = [
                { label: '项目主键', name: 'Id', hidden: true },
                { label: '关系表主键', name: 'OIId', hidden: true },
                { label: '对象主键', name: 'ObjectId', hidden: true },
                { label: '组织机构ID', name: 'OrganizeId', hidden: true },
                { label: '巡检点名称', name: 'ObjName', index: 'ObjName', width: 150, align: 'center', sortable: false },
                { label: '编码', name: 'ObjCode', index: 'ObjCode', width: 100, align: 'center', sortable: false },
                { label: '巡检点地址', name: 'Address', index: 'Address', width: 300, align: 'center', sortable: false },
                {
                    label: "标识方式", name: "FlagWay", index: "FlagWay", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "无标识"; break;
                            case 1: return "rfid芯片"; break;
                            case 2: return "条码"; break;
                            case 3: return "二维码"; break;
                            case 4: return "beacon"; break;
                            default: return cellvalue;
                        }
                    }
                },
                { label: '执行次数', name: 'Frequency', index: 'Frequency', editable: true, editrules: { edithidden: true, required: true, number: true }, edittype: "text", width: 100, align: 'center', sortable: false }
                ];
                break;
        }
        var selectedRowIndex = 0;
        var $gridTable = $("#jqg_Object");
        $gridTable.jqGrid({
            datatype: "local",
            autowidth: true,
            unwritten: false,
            height: 400,
            toolbar: [true, 'top'],
            colModel: _colModel,
            rowNum: "10000",
            rownumbers: true,
            onSelectRow: function (rowid, status) {
                if (rowid && rowid !== selectedRowIndex && selectedRowIndex != 0) {
                    $gridTable.saveRow(selectedRowIndex);
                    $.each(list, function (i, n) {
                        if ($gridTable.getRowData(rowid).Id == n.Id) {
                            list[i].Frequency = $gridTable.getRowData(rowid).Frequency;
                            return false;
                        }
                    });
                }
                //selectedRowIndex = $("#" + this.id).getGridParam('selarrrow');
            },
            gridComplete: function () {
                if (isTrue) { return; }
                $("#" + this.id).setSelection(selectedRowIndex, false);
                var rowid = 0;
                $.each(list, function (i, n) {
                    if (n.Id == _ItemId && n.TypeId == _TypeId) {
                        isTrue = true;
                        $gridTable.addRowData(++rowid, n);
                    }
                });
                isTrue = false;
            },
            ondblClickRow: function (rowid, iRow, iCol, e) {
                $gridTable.editRow(rowid, {
                    keys: true, successfunc: function (response) {
                        $gridTable.jqGrid("saveRow", rowid);
                        $.each(list, function (i, n) {
                            if ($gridTable.getRowData(rowid).Id == n.Id && $gridTable.getRowData(rowid).ObjectId == n.ObjectId) {
                                list[i].Frequency = $gridTable.getRowData(rowid).Frequency;
                                return false;
                            }
                        });
                        return true;
                    }
                });
                selectedRowIndex = rowid;
            }
        });
        if (_TypeId == "644d52f3-772a-421c-9df2-a4ee5ffc2f91") {
            $("#t_jqg_Object").css("height", "36px").append("<div class=\"toolbar\" style=\"margin-top:1px;margin-left:1px;\"><div class=\"btn-group\">"
                               + "<a id=\"lr-deleteObj\" class=\"btn btn-default\" onclick=\"btn_deleteObj()\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</a></div></div>")
        }
        else {
            $("#t_jqg_Object").css("height", "36px").append("<div class=\"toolbar\" style=\"margin-top:1px;margin-left:1px;\"><div class=\"btn-group\">"
                           + "<a id=\"lr-addObj\" class=\"btn btn-default\" onclick=\"btn_addObj()\"><i class=\"fa fa-plus\"></i>&nbsp;新增</a>"
                           + "<a id=\"lr-deleteObj\" class=\"btn btn-default\" onclick=\"btn_deleteObj()\"><i class=\"fa fa-trash-o\"></i>&nbsp;删除</a>"
                           + "</div></div>");
        }
    }

    function GetTree(type) {
        var _url = "";
        var _Div = "";
        var _GridUrl = "";
        var isTrue = false;
        //if ($('#' + type).getCheckedAllNodes() != "") { return; }
        if (type == "Area1" || type == "Area2" || type == "Area3") { _url = "../../PropertyManage/CS_PollingBussiness/Get" + type.substring(0, 4) + "CheckTreeJson"; _Div = type.substring(4, 5) + "Div" }
        else { _url = "../../PropertyManage/CS_PollingBussiness/Get" + type + "CheckTreeJson"; _Div = "Div"; }
        $.SetForm({
            url: _url,
            success: function (data) {
                AllAuthorizeCheckData[type] = $.arrayClone(data);
                var item = {
                    height: $(window).height() - 131,
                    showcheck: true,
                    data: data,
                    oncheckboxclick: function (item, et, s) {
                        if (isTrue) { isTrue = false; return; }
                        _ObjectId = item.id;
                        $(".SchemeAuthorizePanel").css('display', 'none');
                        if (et == 1) {
                            $.ajax({
                                type: "GET",
                                url: "../../PropertyManage/CS_PollingBussiness/GetItemListJson?ObjectId=" + _ObjectId + "&TypeId=" + _TypeId,
                                success: function (data) {
                                    $.each(eval('(' + data + ')'), function (i, n) {
                                        list.push(n);
                                    });
                                }
                            })
                        } else {
                            for (var i = 0; i < list.length; i++) {
                                if (list[i].ObjectId == _ObjectId && list[i].TypeId == _TypeId) {
                                    list.splice(i, 1);
                                    i--;
                                }
                            }
                        }
                    }
                    ,
                    onnodeclick: function (item) {
                        
                        _ObjectId = item.id;
                        if (item.checkstate == 0) {
                            alert("请先勾选该节点");
                            return false;
                        }
                        else if (!!item.checkstate) {
                            $('#Area1Div').css('display', 'block');
                            var $gridTable = $("#jqg_Item");
                            var ids = $gridTable.getDataIDs();
                            $.each(ids, function (i, n) {
                                $gridTable.delRowData(n);
                            })
                            if (_TypeId == "644d52f3-772a-421c-9df2-a4ee5ffc2f91") {
                                $("#lr-add").css('display', 'none');
                            }
                            else { $("#lr-add").css('display', 'block'); }
                            var rowid = 0;
                            $.each(list, function (i, n) {
                                if (list[i].ObjectId == _ObjectId && list[i].TypeId == _TypeId) {
                                    $gridTable.addRowData(++rowid, n);
                                }
                            });
                        }
                    }
                };
                $("#" + type).treeview(item);
                var objId = "";
                $.each(list, function (i, n) {
                    if (n.TypeId == _TypeId && objId.indexOf(n.ObjectId) < 0) {
                        isTrue = true;
                        objId += n.ObjectId + ",";
                        $("#" + type).setCheckedNodeOne(n.ObjectId);
                    }
                });
            }
        });
    }



    function Tabchange(id) {
        GetTree(id.substring(0, id.length - 3));
        $(".SchemeAuthorizePanel").css('display', 'none');
        //$('#' + id).css('display', 'block');
    }

    function TabItem(id) {
        GetItem(id.substring(0, id.length - 3));
        $(".SchemeAuthorizePanel").css('display', 'none');
        //$('#' + id).css('display', 'block');
    }

    function GetItem(type) {
        var _Div = "";
        //var _ItemId = "";
        var _Value = "";
        var isTrue = false;
        $.SetForm({
            url: "../../PropertyManage/CS_PollingBussiness/GetItemCheckTreeJson?type=" + _TypeId,
            success: function (data) {
                AllAuthorizeCheckData[type] = $.arrayClone(data);
                var item = {
                    height: $(window).height() - 131,
                    showcheck: true,
                    data: data,
                    oncheckboxclick: function (item, et, s) {
                        if (isTrue) { isTrue = false; return; }
                        _ItemId = item.id;
                        $(".SchemeAuthorizePanel").css('display', 'none');
                        var $item = $("#" + type + "Div");
                        if (et == 1) {
                            $.ajax({
                                type: "GET",
                                url: "../../PropertyManage/CS_PollingBussiness/GetItemListJson?ItemId=" + _ItemId + "&TypeId=" + _TypeId,
                                success: function (data) {
                                    $.each(eval('(' + data + ')'), function (i, n) {
                                        list.push(n);
                                    });
                                }
                            })
                        } else {
                            for (var i = 0; i < list.length; i++) {
                                if (list[i].Id == _ItemId && list[i].TypeId == _TypeId) {
                                    list.splice(i, 1);
                                    i--;
                                }
                            }
                        }
                    }
                    ,
                    onnodeclick: function (item) {
                        
                        _ItemId = item.id;
                        if (item.checkstate == 0) {
                            alert("请先勾选该节点");
                            return false;
                        }
                        else if (!!item.checkstate) {
                            $('#ItemArea1Div').css('display', 'block');
                            var $gridTable = $("#jqg_Object");
                            $gridTable.GridUnload();
                            GetObjectGrid();
                        }
                    }
                };
                $("#" + type).treeview(item);
                var Itemid = "";
                $.each(list, function (i, n) {
                    if (n.TypeId == _TypeId && Itemid.indexOf(n.Id) < 0) {
                        isTrue = true;
                        Itemid += n.Id + ",";
                        $("#" + type).setCheckedNodeOne(n.Id);
                    }
                });
            }
        });
    }

    function btn_addItem() {
        var objlist = [];
        $.each(list, function (i, n) {
            if (n.ObjectId == _ObjectId) {
                objlist.push(n);
            }
        })
        sessionStorage.setItem("list", JSON.stringify(objlist));
        dialogOpen({
            id: "addItem",
            title: '关联项目',
            url: '/PropertyManage/CS_PollingBussiness/AddItemForm?TypeId=' + _TypeId + "&ObjectId=" + _ObjectId,
            width: "800px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
                $.each(eval('(' + sessionStorage.getItem("addItem") + ')'), function (i, n) {
                    list.push(n);
                });
                var $gridTable = $("#jqg_Item");
                $gridTable.addRowData(($gridTable.jqGrid("getRowData").length + 1), eval('(' + sessionStorage.getItem("addItem") + ')'));
                sessionStorage.removeItem("addItem");
            }
        });
    }

    //删除
    function btn_deleteItem() {
        var $gridTable = $("#jqg_Item");
        var rowid = $gridTable.getGridParam('selrow');
        if (rowid) {
            var id = $gridTable.jqGridRowValue("Id");
            $.each(list, function (i, n) {
                if (n.ObjectId == _ObjectId && n.Id == id) {
                    list.splice(i, 1);
                    return false;
                }
            });
            $gridTable.delRowData(rowid);
        } else {
            dialogMsg('请选择需要删除的项目！', 0);
        }
    }

    function btn_addObj() {
        var objlist = [];
        $.each(list, function (i, n) {
            if (n.Id == _ItemId) {
                objlist.push(n);
            }
        })
        sessionStorage.setItem("list", JSON.stringify(objlist));
        dialogOpen({
            id: "addItem",
            title: '关联项目',
            url: '/PropertyManage/CS_PollingBussiness/AreaForm?TypeId=' + _TypeId + "&ItemId=" + _ItemId,
            width: "800px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
                $.each(eval('(' + sessionStorage.getItem("addItem") + ')'), function (i, n) {
                    list.push(n);
                });
                var $gridTable = $("#jqg_Object");
                $gridTable.GridUnload();
                GetObjectGrid();
                sessionStorage.removeItem("addItem");
            }
        });
    }

    //删除
    function btn_deleteObj() {
        var $gridTable = $("#jqg_Object");
        var rowid = $gridTable.getGridParam('selrow');
        if (rowid) {
            var id = $gridTable.jqGridRowValue("ObjectId");
            $.each(list, function (i, n) {
                if (n.Id == _ItemId && n.ObjectId == id) {
                    list.splice(i, 1);
                    return false;
                }
            });
            $gridTable.delRowData(rowid);
        } else {
            dialogMsg('请选择需要删除的项目！', 0);
        }
    }

    function btn_addBillInstance() {
        isBool = true;
        $("#publish_panel").animate({ top: 50, speed: 2000 });
        return false;
    }

    function btn_success() {
        if (list.length < 1) {
            dialogMsg('最少选择一条数据', 0);
            return false;
        }
        var model = $("#step-1").GetWebControls(keyValue);

        if ($("#ExecRole").getCheckedAllNodes().length <= 0) {
            dialogMsg('请选择执行角色！', -1);
            return false;
        }
        model["ExecRole"] = $("#ExecRole").getCheckedAllNodes().join(",");
        model["ExecRoleType"] = $("#ExecRoleType").val();
        var _BillInstance = ""
        if (isBool) {
            if (!$('#publish_panel').Validform()) {
                return false;
            }
            var postData = $("#publish_panel").GetWebControls();
            postData["BeginDate"] += " " + postData["BeginTime"];
            postData["EndDate"] += " " + postData["EndTime"];
            _BillInstance = JSON.stringify(postData);
        }
        var RelationOI = [];
        $.each(list, function (i, n) {
            var a = { Id: n.OIId, ItemId: n.Id, TypeId: n.TypeId, ObjectId: n.ObjectId, Frenquency: n.Frequency, OrganizeId: n.OrganizeId };
            RelationOI.push(a);
        });
        $.SaveForm({
            url: "../../PropertyManage/CS_PollingBussiness/SavePerformanceForm",
            param: { keyValue: keyValue, RelationOI: JSON.stringify(RelationOI), Instance: _BillInstance, model: JSON.stringify(model) },
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
            }
        });
    }

    //选择执行角色类别
    function RoleTypeChange() {
        GetRole();
    }


    function GetRole() {
        $.SetForm({
            url: "../../BaseManage/Role/GetRoleCheckTreeJson?type=" + $("#ExecRoleType").val(),
            success: function (data) {
                var item = {
                    showcheck: true,
                    data: data
                };
                $("#ExecRole").treeview(item);
            }
        });
    }

</script>
<div class="widget-body" id="tempbody">
    <div id="wizard" class="wizard" data-target="#wizard-steps" style="border-left: none; border-top: none; border-right: none;">
        <ul class="steps">
            <li data-target="#step-1" class="active"><span class="step">1</span>基础设置<span class="chevron"></span></li>
            <li data-target="#step-2"><span class="step">2</span>巡检对象<span class="chevron"></span></li>
            <li data-target="#step-3"><span class="step">3</span>巡检项目<span class="chevron"></span></li>
            <li data-target="#step-4"><span class="step">4</span>创建任务<span class="chevron"></span></li>
        </ul>
    </div>
    <div class="step-content" id="wizard-steps" style="border-left: none; border-bottom: none; border-right: none;">
        <div class="step-pane active" id="step-1" style="margin-left: 0px; margin-top: 15px; margin-right: 30px;">
            <table id="tempform" class="form">
                <tr>
                    <th class="formTitle">业务编号<font face="宋体">*</font></th>
                    <td class="formValue">
                        <input id="Code" type="text" class="form-control" onblur="$.ExistField(this.id, '../../PropertyManage/CS_PollingBussiness/ExistCode')" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">业务名称<font face="宋体">*</font></th>
                    <td class="formValue">
                        <input id="Name" type="text" class="form-control" onblur="$.ExistField(this.id, '../../PropertyManage/CS_PollingBussiness/ExistName')" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">巡检专业<font face="宋体">*</font></th>
                    <td class="formValue">
                        <div id="PollingType" class="checkbox user-select">
                            <label>
                                <input id="be7352e1-4ace-4fe9-bc0f-767aa70e3ac0" name="checktype" type="checkbox" />
                                保安巡检
                            </label>
                            <label>
                                <input id="7c38d876-2f54-4783-b26a-b194f2bad634" name="checktype" type="checkbox" />
                                保洁巡检
                            </label>
                            <label>
                                <input id="d56675f0-e574-42a5-9d2a-6874672bf561" name="checktype" type="checkbox" />
                                消防巡检
                            </label>
                            <label>
                                <input id="9b5a3e03-499b-4003-9b11-9558191d7b2c" name="checktype" type="checkbox" />
                                装修巡检
                            </label>
                            <label>
                                <input id="fa7addca-b7d8-4a42-91ce-8499323013c7" name="checktype" type="checkbox" />
                                商铺巡检
                            </label>
                            <label>
                                <input id="644d52f3-772a-421c-9df2-a4ee5ffc2f91" name="checktype" type="checkbox" />
                                设备巡检
                            </label>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">绩效分<font face="宋体">*</font></th>
                    <td class="formValue">
                        <input id="Goals" type="number" class="form-control" isvalid="yes" checkexpession="NotNull" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle" valign="top" style="padding-top: 4px;">备注</th>
                    <td class="formValue">
                        <textarea id="Memo" class="form-control" style="height: 150px;"></textarea>
                    </td>
                </tr>
                <tr hidden="hidden">
                    <th class="formTitle">执行角色类别<font face="宋体">*</font></th>
                    <td class="formValue">
                        <select id="ExecRoleType" style="border: 0px;" onchange="RoleTypeChange();">
                            <option value="1" selected="selected">角色</option>
                            <option value="2">岗位</option>
                            <option value="3">用户组</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">选择执行角色<font face="宋体">*</font></th>
                    <td class="formValue">
                        <div id="ExecRole"></div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="step-pane" id="step-2">
            <div id="PollingObject">
                <div class="standtabborder">
                    <div id="area1" class="standtab" onclick="$.standTabchange(this, 'Area1'); _TypeId = 'be7352e1-4ace-4fe9-bc0f-767aa70e3ac0'; Tabchange('Area1Div'); ">
                        保安巡检
                    </div>
                    <div id="area2" class="standtab" onclick="$.standTabchange(this, 'Area2'); _TypeId = '7c38d876-2f54-4783-b26a-b194f2bad634'; Tabchange('Area2Div');">
                        保洁巡检
                    </div>
                    <div id="area3" class="standtab " onclick="$.standTabchange(this, 'Area3'); _TypeId = 'd56675f0-e574-42a5-9d2a-6874672bf561'; Tabchange('Area3Div');">
                        消防巡检
                    </div>
                    <div id="decorate1" class="standtab " onclick="$.standTabchange(this, 'DecorateBill'); _TypeId = '9b5a3e03-499b-4003-9b11-9558191d7b2c'; Tabchange('DecorateBillDiv');">
                        装修单
                    </div>
                    <div id="room1" class="standtab " onclick="$.standTabchange(this, 'Room'); _TypeId = 'fa7addca-b7d8-4a42-91ce-8499323013c7'; Tabchange('RoomDiv');">
                        房间
                    </div>
                    <div id="device1" class="standtab " onclick="$.standTabchange(this, 'Device'); _TypeId = '644d52f3-772a-421c-9df2-a4ee5ffc2f91'; Tabchange('DeviceDiv');">
                        设备
                    </div>
                </div>
                <div id="Area1" style="display: none;" class="standtab-pane"></div>
                <div id="Area2" style="display: none;" class="standtab-pane"></div>
                <div id="Area3" style="display: none;" class="standtab-pane"></div>
                <div id="DecorateBill" style="display: none;" class="standtab-pane"></div>
                <div id="Room" style="display: none;" class="standtab-pane"></div>
                <div id="Device" style="display: none;" class="standtab-pane"></div>

                <div id="DesignateMemberlist" style="margin: 0px; border-right: none; border-left: none; border-bottom: none; background-color: #fff; overflow: auto; padding-bottom: 10px;height:528px;">
                    <div id="Area1Div" class="SchemeAuthorizePanel">
                        <div class="flow-portal-panel-title" style="margin-bottom:10px;"><i class="fa fa-paw"></i>&nbsp;&nbsp;项目列表</div>
                        <table id="jqg_Item"></table>
                    </div>
                </div>
                @*<div id="Treebackground" style="position: fixed; top: 91px; left: 0px; z-index: 2; width: 1100px; height: 528px; background: #000; filter: alpha(opacity=10); opacity: 0.1;"></div>*@
            </div>
        </div>
        <div class="step-pane" id="step-3">
            <div id="PollingItem">
                <div class="standtabborder" style="height:528px;">
                    <div id="Itemarea1" class="standtab" onclick="$.standTabchange(this, 'ItemArea1'); _TypeId = 'be7352e1-4ace-4fe9-bc0f-767aa70e3ac0'; TabItem('ItemArea1Div')">
                        保安巡检
                    </div>
                    <div id="Itemarea2" class="standtab" onclick="$.standTabchange(this, 'ItemArea2'); _TypeId = '7c38d876-2f54-4783-b26a-b194f2bad634'; TabItem('ItemArea2Div')">
                        保洁巡检
                    </div>
                    <div id="Itemarea3" class="standtab " onclick="$.standTabchange(this, 'ItemArea3'); _TypeId = 'd56675f0-e574-42a5-9d2a-6874672bf561'; TabItem('ItemArea3Div')">
                        消防巡检
                    </div>
                    <div id="Itemdecorate1" class="standtab " onclick="$.standTabchange(this, 'ItemDecorateBill'); _TypeId = '9b5a3e03-499b-4003-9b11-9558191d7b2c'; TabItem('ItemDecorateBillDiv')">
                        装修巡检
                    </div>
                    <div id="Itemroom1" class="standtab " onclick="$.standTabchange(this, 'ItemRoom'); _TypeId = 'fa7addca-b7d8-4a42-91ce-8499323013c7'; TabItem('ItemRoomDiv')">
                        商铺巡检
                    </div>
                    <div id="Itemdevice1" class="standtab " onclick="$.standTabchange(this, 'ItemDevice'); _TypeId = '644d52f3-772a-421c-9df2-a4ee5ffc2f91'; TabItem('ItemDeviceDiv')">
                        设备巡检
                    </div>
                </div>
                <div id="ItemArea1" style="display: none;" class="standtab-pane"></div>
                <div id="ItemArea2" style="display: none;" class="standtab-pane"></div>
                <div id="ItemArea3" style="display: none;" class="standtab-pane"></div>
                <div id="ItemDecorateBill" style="display: none;" class="standtab-pane"></div>
                <div id="ItemRoom" style="display: none;" class="standtab-pane"></div>
                <div id="ItemDevice" style="display: none;" class="standtab-pane"></div>

                <div id="ItemDesignateMemberlist" style="margin: 0px; border-right: none; border-left: none; border-bottom: none; background-color: #fff; overflow: auto; padding-bottom: 10px;height:528px;">
                    <div id="ItemArea1Div" class="SchemeAuthorizePanel">
                        <div class="flow-portal-panel-title" style="margin-bottom:10px;"><i class="fa fa-paw"></i>&nbsp;&nbsp;对象列表</div>
                        <table id="jqg_Object"></table>
                    </div>
                </div>
            </div>
        </div>
        <div class="step-pane" id="step-4" style="margin-top: 15px; margin-right: 30px;">
            <div style="height: 400px;">
                <div class="drag-tip" style="text-align: center; padding-top: 50px;">
                    <i class="fa fa-check-circle" style="font-size: 204px; color: #0FA74F;"></i>
                    <div id="finish-msg" style="font-weight: bold; font-size: 24px; color: #0FA74F; margin-top: 20px;">
                    </div>
                    <p style="color: #666; font-size: 12px; margin-top: 10px;">
                        <a href="#" onclick="btn_addBillInstance()" id="publish_btn">创建标准工单</a>
                    </p>
                </div>
                <div id="publish_panel" style="position: absolute; height: 350px; top: 650px; z-index: 100; background: #ffffff; margin-top: 15px; margin-right: 30px;">
                    <table class="form">
                        <tr>
                            <th class="formTitle">工单开始日期<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="BeginDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'EndDate\')}'})" isvalid="yes" checkexpession="NotNull" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">工单结束日期<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="EndDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({ minDate: '#F{$dp.$D(\'BeginDate\')}' })" isvalid="yes" checkexpession="NotNull" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">时间段<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="BeginTime" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'H:mm:ss', maxDate: '#F{$dp.$D(\'EndTime\')}' })" isvalid="yes" checkexpession="NotNull" />至
                                <input id="EndTime" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'H:mm:ss', minDate: '#F{$dp.$D(\'BeginTime\')}' })" isvalid="yes" checkexpession="NotNull" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">频次<font face="宋体">*</font></th>
                            <td class="formValue">
                                <div class="checkbox">
                                    <label>
                                        <input id="UnitNum" type="number" isvalid="yes" checkexpession="NotNull" value="1" readonly="readonly" min="1" style="width:40px;" />
                                        <select id="Unit" style="border: 0px;">
                                            <option value="0">天</option>
                                            <option value="1">周</option>
                                            <option selected="selected" value="2">月</option>
                                            <option value="3">季</option>
                                            <option value="4">年</option>
                                        </select>
                                        <input type="number" style="width:40px;" id="Frenquency" min="1" isvalid="yes" checkexpession="NotNull" />次
                                    </label>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="form-button" id="wizard-actions">
    <a id="btn_last" disabled class="btn btn-default btn-prev">上一步</a>
    <a id="btn_next" class="btn btn-default btn-next">下一步</a>
    <a id="btn_finish" disabled onclick="btn_success()" class="btn btn-success">完成</a>
</div>
<style>
    body {
        overflow: hidden;
    }

    .editviewtitle {
        position: fixed !important;
        top: 117px;
        right: 11px;
        width: 50px;
        z-index: 1000;
    }

    .standtab-pane {
        width: 224px;
        border-right: 1px solid #ccc;
        float: left;
    }

    .SchemeAuthorizePanel {
        width: 828px;
        float: left;
        display: none;
    }

    .card-box.active {
        background: url(../../Content/Images/item_close.png) right top no-repeat !important;
    }
</style>
